package com.kfm.am.exec;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiFunction;

public class Exec02 {

    public static void main(String[] args) {
        // 给定两个字符串 `s` 和 `t` ，编写一个函数来判断 `t` 是否是 `s` 的字母异位词。
        String s = "abcdefgd";
        String t = "abcdefd";
//        HashMap<Character, Integer> sHashMap = getHashMap(s);
//        HashMap<Character, Integer> tHashMap = getHashMap(t);
//        System.out.println(sHashMap.equals(tHashMap));
        Character[] characters = new Character[]{'k', 'l', 's'};
        char[] sCharArray = s.toCharArray();
        char[] tCharArray = t.toCharArray();
        System.out.println();
        String[] strings = s.split("");
        String[] tStrings = t.split("");

        List<char[]> list2 = Arrays.asList(sCharArray);
        List<Character> list1 = Arrays.asList(characters);
        // Arrays.asList(strings) 返回的List对象是在 Arrays 里面定义的一个内部类 没有重写 removeAll
        List<String > list = new ArrayList<>(Arrays.asList(strings));
        List<String > tList = new ArrayList<>(Arrays.asList(tStrings));
        list.removeAll(tList); // 删除两个集合的交集
        System.out.println(list.size() == 0); //

//        Arrays.sort(sCharArray);
//        Arrays.sort(tCharArray);
//        System.out.println(Arrays.equals(sCharArray, tCharArray));



    }

    public static HashMap<Character, Integer> getHashMap(String s) {
        HashMap<Character, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            hashMap.compute(s.charAt(i), new BiFunction<Character, Integer, Integer>() {
                @Override
                public Integer apply(Character character, Integer integer) {
                    return integer == null ? 1 : integer + 1;
                }
            });
        }
        return hashMap;
    }
}
